from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-17 19:10:41.079865
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 17, Mar, 2021
Time: 19:10:45
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.9221
Nobs: 233.000 HQIC: -47.7176
Log likelihood: 2736.21 FPE: 1.10473e-21
AIC: -48.2552 Det(Omega_mle): 7.56835e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.458388 0.131926 3.475 0.001
L1.Burgenland 0.065943 0.066880 0.986 0.324
L1.Kärnten -0.210489 0.056755 -3.709 0.000
L1.Niederösterreich 0.135893 0.149246 0.911 0.363
L1.Oberösterreich 0.251368 0.134931 1.863 0.062
L1.Salzburg 0.212768 0.072171 2.948 0.003
L1.Steiermark 0.110484 0.096215 1.148 0.251
L1.Tirol 0.110838 0.064970 1.706 0.088
L1.Vorarlberg -0.003302 0.059580 -0.055 0.956
L1.Wien -0.117615 0.123714 -0.951 0.342
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.469070 0.157009 2.988 0.003
L1.Burgenland 0.018911 0.079596 0.238 0.812
L1.Kärnten 0.349059 0.067546 5.168 0.000
L1.Niederösterreich 0.091744 0.177622 0.517 0.605
L1.Oberösterreich -0.106988 0.160586 -0.666 0.505
L1.Salzburg 0.188002 0.085893 2.189 0.029
L1.Steiermark 0.195342 0.114509 1.706 0.088
L1.Tirol 0.131868 0.077323 1.705 0.088
L1.Vorarlberg 0.158006 0.070908 2.228 0.026
L1.Wien -0.482128 0.147236 -3.275 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.306407 0.061650 4.970 0.000
L1.Burgenland 0.094340 0.031253 3.019 0.003
L1.Kärnten -0.018096 0.026522 -0.682 0.495
L1.Niederösterreich 0.065155 0.069743 0.934 0.350
L1.Oberösterreich 0.295374 0.063054 4.684 0.000
L1.Salzburg 0.012491 0.033726 0.370 0.711
L1.Steiermark -0.006499 0.044962 -0.145 0.885
L1.Tirol 0.069237 0.030361 2.280 0.023
L1.Vorarlberg 0.102765 0.027842 3.691 0.000
L1.Wien 0.085036 0.057812 1.471 0.141
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.219772 0.065734 3.343 0.001
L1.Burgenland 0.000451 0.033324 0.014 0.989
L1.Kärnten 0.016009 0.028279 0.566 0.571
L1.Niederösterreich 0.035695 0.074364 0.480 0.631
L1.Oberösterreich 0.397909 0.067231 5.919 0.000
L1.Salzburg 0.081330 0.035960 2.262 0.024
L1.Steiermark 0.174710 0.047941 3.644 0.000
L1.Tirol 0.040950 0.032372 1.265 0.206
L1.Vorarlberg 0.081031 0.029686 2.730 0.006
L1.Wien -0.047695 0.061642 -0.774 0.439
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.515830 0.130053 3.966 0.000
L1.Burgenland 0.063482 0.065931 0.963 0.336
L1.Kärnten 0.004094 0.055949 0.073 0.942
L1.Niederösterreich -0.029534 0.147128 -0.201 0.841
L1.Oberösterreich 0.148016 0.133016 1.113 0.266
L1.Salzburg 0.070208 0.071147 0.987 0.324
L1.Steiermark 0.093663 0.094850 0.987 0.323
L1.Tirol 0.222407 0.064048 3.473 0.001
L1.Vorarlberg 0.027666 0.058734 0.471 0.638
L1.Wien -0.105064 0.121958 -0.861 0.389
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181236 0.096316 1.882 0.060
L1.Burgenland -0.017761 0.048828 -0.364 0.716
L1.Kärnten -0.010873 0.041436 -0.262 0.793
L1.Niederösterreich 0.010410 0.108962 0.096 0.924
L1.Oberösterreich 0.406700 0.098511 4.128 0.000
L1.Salzburg 0.005736 0.052691 0.109 0.913
L1.Steiermark -0.010144 0.070245 -0.144 0.885
L1.Tirol 0.164000 0.047433 3.457 0.001
L1.Vorarlberg 0.052577 0.043498 1.209 0.227
L1.Wien 0.223821 0.090321 2.478 0.013
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.243524 0.122590 1.986 0.047
L1.Burgenland 0.030839 0.062147 0.496 0.620
L1.Kärnten -0.044398 0.052738 -0.842 0.400
L1.Niederösterreich -0.052773 0.138684 -0.381 0.704
L1.Oberösterreich -0.050649 0.125383 -0.404 0.686
L1.Salzburg 0.075397 0.067064 1.124 0.261
L1.Steiermark 0.374399 0.089407 4.188 0.000
L1.Tirol 0.453398 0.060372 7.510 0.000
L1.Vorarlberg 0.160573 0.055363 2.900 0.004
L1.Wien -0.186148 0.114959 -1.619 0.105
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.122097 0.145749 0.838 0.402
L1.Burgenland 0.030506 0.073888 0.413 0.680
L1.Kärnten -0.059237 0.062702 -0.945 0.345
L1.Niederösterreich 0.203486 0.164884 1.234 0.217
L1.Oberösterreich -0.029452 0.149070 -0.198 0.843
L1.Salzburg 0.245976 0.079733 3.085 0.002
L1.Steiermark 0.144976 0.106297 1.364 0.173
L1.Tirol 0.039922 0.071778 0.556 0.578
L1.Vorarlberg 0.074005 0.065823 1.124 0.261
L1.Wien 0.228676 0.136677 1.673 0.094
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.577338 0.079008 7.307 0.000
L1.Burgenland -0.032388 0.040053 -0.809 0.419
L1.Kärnten -0.016270 0.033990 -0.479 0.632
L1.Niederösterreich 0.016702 0.089381 0.187 0.852
L1.Oberösterreich 0.313710 0.080808 3.882 0.000
L1.Salzburg 0.011582 0.043222 0.268 0.789
L1.Steiermark -0.012201 0.057622 -0.212 0.832
L1.Tirol 0.080372 0.038909 2.066 0.039
L1.Vorarlberg 0.115049 0.035681 3.224 0.001
L1.Wien -0.045759 0.074090 -0.618 0.537
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.134217 0.045129 0.191841 0.237312 0.067083 0.130896 -0.030065 0.163242
Kärnten 0.134217 1.000000 0.005775 0.196339 0.167328 -0.102824 0.146816 0.017166 0.307291
Niederösterreich 0.045129 0.005775 1.000000 0.267796 0.059932 0.266333 0.154533 0.050994 0.313407
Oberösterreich 0.191841 0.196339 0.267796 1.000000 0.291084 0.263451 0.093774 0.072213 0.138047
Salzburg 0.237312 0.167328 0.059932 0.291084 1.000000 0.117956 0.063697 0.086789 -0.003243
Steiermark 0.067083 -0.102824 0.266333 0.263451 0.117956 1.000000 0.127533 0.120844 -0.120191
Tirol 0.130896 0.146816 0.154533 0.093774 0.063697 0.127533 1.000000 0.171024 0.145461
Vorarlberg -0.030065 0.017166 0.050994 0.072213 0.086789 0.120844 0.171024 1.000000 0.021452
Wien 0.163242 0.307291 0.313407 0.138047 -0.003243 -0.120191 0.145461 0.021452 1.000000